import {Component} from 'react';
import {
  Boxs,
  Avatar
} from 'saltui';

const {HBox, Box} = Boxs;

import DB from '../../app/db';

export default class UserInfo extends Component {

  constructor(props) {
    super(props);
    this.state = {
      user: {}
    };

  }

  componentDidMount() {
    this.getUserInfo(this.props.userId);
  }

  componentWillReceiveProps(newProps) {
    // alert("componentWillReceiveProps : " + newProps.userId);
    this.getUserInfo(newProps.userId);
  }

  getUserInfo(paramUserId) {
    const userId = paramUserId ? paramUserId : '';
    var param = {
      userId: userId,
      corpId: '0',
    }
    DB.CommonAPI.currentUserInfo(param).then((content) => {
      // debugger;
      const user = content;
      // this.user = user;
      this.setState({user});
      // return user;
    }).catch((error) => {

    });

  }

  render() {
    // alert(this.props.userId);
    // const user = this.getUserInfo();
    return (

      <div className="dd-t-list-wrap">
        <HBox vAlign="center">
          <HBox flex={1} className="t-FBAC">
            <Box className="t-MR10">
              <Avatar name={this.state.user.cnName}/>
            </Box>
            <Box className="dd-t-list-text-content" flex={1}>
              <div className="dd-t-list-title t-FBAC">
                <span>{this.state.user.cnName}</span>
              </div>
              <div className="dd-t-list-text t-FBAC">
                <span>{this.state.user.orgName}</span>
              </div>
            </Box>
          </HBox>
        </HBox>
      </div>
    );
  }
}
